const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");

const htmlPlugin = new HtmlWebpackPlugin({
  template: path.join(__dirname, "./src/index.html"),
  filename: "index.html"
});

module.exports = {
  mode: "development",
  plugins: [htmlPlugin],
  module: {
    //所有第三方模块,配置规则
    rules: [
      //第三方匹配规则
      { test: /\.js|jsx$/, use: "babel-loader", exclude: /node_modules/ }, //exclude排除项
      { test: /\.css$/, use: ["style-loader", "css-loader"] }, //打包处理.css文件
      { test: /\.ttf|woff|eot|svg$/, use: "url-loader" }, //打包处理字体文件
      {
        test: /\.scss$/,
        use: [
          "style-loader",
          "css-loader?modules&loaclIdentName=[path][name]-[loacl]-[hash:5]",
          "sass-loader"
        ]
      } //打包处理scss文件
    ]
  },
  resolve: {
    extensions: [".js", ".jsx", ".json"], //自动补全后缀名,可以不写了
    alias: {
      //表示别名
      "@": path.join(__dirname, "./src") //@ 表示项目根目录 ./src
    }
  }
};
